<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>统战成员学习平台</title>
    <div id="main">
<!--        <div>{{code}}</div>-->
<!--        <button @click="wxLogin()">企业微信登录</button>-->
<!--        <button @click="accountLogin()">账号登录</button>-->
<!--        <button @click="clear()">clear</button>-->
    </div>
    <script type="text/javascript" src="./script/api.js"></script>
    <script type="text/javascript" src="./script/vue.min.js"></script>
    <script type="text/javascript" src="./script/layer_mobile/layer.js"></script>
    <script type="text/javascript" src="./script/common.js"></script>
    <script type="text/javascript">

        new Vue({
            el: '#main',
            data: {
                code: ''
            },
            mounted: function () {
                var $this = this;
                apiready = function () {
                    var code = $api.getStorage('CODE');
                    $this.code = code;
                    if (code && OPEN_WX_LOGIN) {
                        $api.setStorage('CODE', '');

                        $this.wxLogin();

                    } else {
                        api.openWin({
                            name: 'index_win',
                            url: 'html/index_win.html',
                            slidBackEnabled: false,
                            animation: {
                                type: 'none',
                                duration: 0
                            }
                        });
                    }
                }
            },
            methods: {
                wxLogin: function () {
                    var $this = this;
                    if (!$this.code) {
                        msgUtil.toast({mag: '获取企业微信code失败'});
                        return;
                    }

                    var loginLoading = msgUtil.loading();
                    post('/client/wechat/wechatLogin?code=' + $this.code, {}, function (ret) {
                        msgUtil.close(loginLoading);
                        if (ret.isSuccess) {
                            var usrNetId = ret.data.usrNetId;
                            var usrAccount = ret.data.usrAccount;

                            if (!usrNetId) {
                                msgUtil.toast({msg: '获取企业微信用户信息失败：usrNetId'});
                                return;
                            }

                            if (ret.code == '221') {
                                api.openWin({
                                    name: 'binding',
                                    url: 'web_adapter/binding.html',
                                    pageParam: {
                                        usrNetId: usrNetId
                                    }
                                });
                            } else {
                                $api.setStorage(_.USERINFO, ret.data);
                                api.openWin({
                                    name: 'index_win',
                                    url: 'html/index_win.html',
                                    slidBackEnabled: false,
                                    animation: {
                                        type: 'none',
                                        duration: 0
                                    }
                                });
                            }
                        } else {
                            msgUtil.toast({msg: ret.message});
                        }

                    });
                },
                accountLogin: function () {
                    api.openWin({
                        name: 'binding',
                        url: 'html/login.html'
                    })
                },
                clear: function () {
                    $api.setStorage(_.USERINFO, '');
                    $api.setStorage('CODE', '');
                }
            }
        });

    </script>
</head>

<body>
</body>

</html>
